 <!--
 * @Author: zeng_ze
 * @Date: 2020-1-2
 * @Description: 系统管理 -> 定时任务 -> 调度日志
 -->
<template>
  <div>
    <fks-query-page
      v-loading="loading"
      :data="tableData"
      :total="total"
      :page-size.sync="pageSize"
      :current-page.sync="currentPage"
      layout="total, sizes, prev, pager, next, jumper"
      :page-sizes="[15, 20, 50, 100]"
      element-loading-text="加载中"
      table-name="调度日志"
      @query="getData"
    >
      <template slot="search">
        <fks-search-item label="执行器">
          <fks-select v-model="actuator" clearable>
            <fks-option label="队列执行器" value="队列执行器" />
          </fks-select>
        </fks-search-item>
        <fks-search-item label="状态">
          <fks-select v-model="status" clearable>
            <fks-option label="成功" value="成功" />
            <fks-option label="失败" value="失败" />
            <fks-option label="进行中" value="进行中" />
          </fks-select>
        </fks-search-item>
        <fks-search-item label="任务">
          <fks-select v-model="tasks" clearable>
            <fks-option label="全部" value="全部" />
          </fks-select>
        </fks-search-item>
        <fks-search-item :span="24" label="调度时间">
          <fks-time-span-pick
            :start-time.sync="startDate"
            value-format="yyyy-MM-dd"
            :end-time.sync="endDate"
          />
        </fks-search-item>
      </template>
      <template slot="button">
        <fks-button type="primary" @click="clear"> 清理日志 </fks-button>
      </template>
      <template>
        <fks-table-column type="index" align="center">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </fks-table-column>
        <fks-table-column prop="taskId" label="任务ID" />
        <fks-table-column
          prop="dispatchDate"
          label="调度时间"
          min-width="160"
        />
        <fks-table-column prop="dispatchResult" label="调度结果">
          <!-- 调度结果判断 -->
          <template slot-scope="scope">
            <fks-tag v-if="scope.row.dispatchResult == '0'" type="success">
              成功
            </fks-tag>
            <fks-tag v-if="scope.row.dispatchResult == '1'" type="danger">
              失败
            </fks-tag>
            <fks-tag v-if="scope.row.dispatchResult == '2'" type="danger">
              进行中
            </fks-tag>
          </template>
        </fks-table-column>
        <fks-table-column prop="dispatchDesc" label="调度备注">
          <template slot-scope="scope">
            <fks-button type="text" @click="view(scope.row)"> 查看 </fks-button>
          </template>
        </fks-table-column>
        <fks-table-column prop="executeDate" label="执行时间" min-width="160" />
        <fks-table-column prop="executeresult" label="执行结果">
          <!-- 执行结果判断 -->
          <template slot-scope="scope">
            <fks-tag v-if="scope.row.executeresult == '0'" type="success">
              成功
            </fks-tag>
            <fks-tag v-if="scope.row.executeresult == '1'" type="danger">
              失败
            </fks-tag>
            <fks-tag v-if="scope.row.executeresult == '2'" type="danger">
              进行中
            </fks-tag>
          </template>
        </fks-table-column>
        <fks-table-column prop="executeDesc" label="执行备注" />
        <fks-table-column
          :label="LANG.OPERATION"
          header-align="center"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <fks-button type="text" @click="execute(scope.row)">
              执行日志
            </fks-button>
          </template>
        </fks-table-column>
      </template>
    </fks-query-page>
    <!-- 调度备注 查看 -->
    <fks-dialog
      :visible.sync="viewVisible"
      :append-to-body="true"
      destroy-on-close
      title="调度备注"
    >
      <fks-form ref="viewForm" :model="viewForm" :rules="rules" status-icon>
        <fks-form-item :span="12" lead label="任务触发类型" prop="triggerType">
          <fks-input v-model="viewForm.triggerType" :disabled="true" />
        </fks-form-item>
        <fks-form-item :span="12" label="调度机器" prop="dispatchIp">
          <fks-input v-model="viewForm.dispatchIp" :disabled="true" />
        </fks-form-item>
        <fks-form-item
          :span="12"
          lead
          label="执行器-注册方式"
          prop="registerWay"
        >
          <fks-input v-model="viewForm.taskDesc" :disabled="true" />
        </fks-form-item>

        <div style="text-align: right">
          <fks-button type="primary" @click="saveView">
            {{ LANG.CONFIRM }}
          </fks-button>
        </div>
      </fks-form>
    </fks-dialog>
    <!-- 清理日志 -->
    <fks-dialog
      :visible.sync="clearVisible"
      :append-to-body="true"
      destroy-on-close
      title="清理日志"
    >
      <fks-form ref="clearForm" :model="clearForm" :rules="rules" status-icon>
        <fks-form-item :span="12" lead label="执行器" prop="actuator">
          <fks-input v-model="clearForm.actuator" maxlength="50" />
        </fks-form-item>
        <fks-form-item :span="12" label="任务" prop="tasks">
          <fks-input v-model="clearForm.tasks" maxlength="50" />
        </fks-form-item>
        <fks-form-item :span="12" lead label="清理方式" prop="clearWay">
          <fks-select v-model="clearForm.clearWay" style="width: 100%">
            <fks-option label="清理一个月之前的日志数据" value="1" />
          </fks-select>
        </fks-form-item>

        <div style="text-align: right">
          <fks-button type="primary" plain @click="cancel">
            {{ LANG.CANCEL }}
          </fks-button>
          <fks-button type="primary" @click="save">
            {{ LANG.SAVE }}
          </fks-button>
        </div>
      </fks-form>
    </fks-dialog>
  </div>
</template>
 
<script>
import Mix from '@/mixins/module'
export default {
  name: 'DispatchLogs',
  components: {},
  mixins: [Mix],
  data() {
    return {
      //执行器
      actuator: '',
      //状态
      status: '',
      //任务
      tasks: '',
      //调度时间
      startDate: '',
      endDate: '',
      //调度备注 查看
      viewVisible: false,
      clearVisible: false,
      //调度备注 查看 表单
      viewForm: {
        triggerType: '',
        dispatchIp: '',
        registerWay: ''
      },
      //清理日志 表单
      clearForm: {
        actuator: '',
        tasks: '',
        clearWay: ''
      },
      currentPage: 1,
      total: 0,
      pageSize: 15,
      loading: false,
      tableData: [
        {
          taskId: '10',
          dispatchDate: '2020-01-02 05:00:00',
          dispatchResult: '1',
          executeDate: '2020-01-02 05:00:00',
          executeresult: '1',
          executeDesc: '无'
        },
        {
          taskId: '9',
          dispatchDate: '2020-01-02 05:00:00',
          dispatchResult: '0',
          executeDate: '2020-01-02 05:00:00',
          executeresult: '0',
          executeDesc: '无'
        }
      ]
    }
  },
  computed: {
    //验证规则
    rules() {
      return {}
    }
  },
  created() {},
  methods: {
    getData() {},
    //执行日志 参数row
    execute() {},
    //查看 调度结果
    view() {
      this.viewVisible = true
    },
    //确认 调度结果
    saveView() {
      this.viewVisible = false
    },
    //清理日志 保存
    save() {},
    clear() {
      this.clearVisible = true
    },
    cancel() {
      this.clearVisible = false
    }
  }
}
</script>
<style lang="scss" scoped>
</style>